package cn.tedu.supermarket.service;

import cn.tedu.supermarket.entity.AddressDTO;
import cn.tedu.supermarket.entity.OrdersDTO;
import cn.tedu.supermarket.entity.User;
import cn.tedu.supermarket.mapper.AddressMapper;
import cn.tedu.supermarket.mapper.OrdersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.ui.Model;
import java.util.ArrayList;
import java.util.List;
@Component
public class SelectByStatus {
    @Autowired
    OrdersMapper ordersMapper;
    @Autowired
    AddressMapper addressMapper;
    public void selectByStatus(User user, Model model,String status){
        int[] arr = ordersMapper.selectAddressIdByUserId(user.getId());
        List<AddressDTO> address = new ArrayList<>();
        for (int i = 0; i < arr.length; i++) {
            AddressDTO addressDTO = addressMapper.selectById(arr[i]);
            address.add(addressDTO);
        }
        model.addAttribute("address",address);
        List<OrdersDTO> list = ordersMapper.selectByStatus(user.getId(),status);
        model.addAttribute("list",list);
    }
}
